# -*- coding:utf-8 -*-
# author: helili
# @Time: 2020/9/23 上午11:35

import json
import yaml


def get_yam(home_yaml):
    """
    解析yaml文件
    :param home_yaml: yaml文件路径
    :return: json对象
    """
    try:
        with open(home_yaml, encoding='utf-8') as f:
            x = yaml.load(f, Loader=yaml.FullLoader)
            return x
    except FileNotFoundError:
        print("找不到文件")


def write2yaml(response, file):
    try:
        data = json.loads(response)
        stream = open(file, 'w')
        yml = yaml.safe_dump(data, stream=stream, default_flow_style=False)
        return yml
    except FileNotFoundError:
        print("找不到文件")


def get_json(home_json):
    try:
        with open(home_json, encoding='utf-8') as f:
            x = json.load(f)
            return x
    except FileNotFoundError:
        print("找不到文件")
